import { styled } from "@linaria/react"
import { Image, View, Text } from "@tarojs/components"

import RatingStars from "@/components/RatingStars"
import Taro from "@tarojs/taro"

export default function RestaurantItem({ restaurant }) {
  const {id, name, numOfScore, picture_url, score, start_time, end_time} = restaurant;

  return (
    <RestaurantItemView onClick={() => Taro.navigateTo({url: "/pages/restaurant/index?id="+id})}>
      <RestaurantImage src={ picture_url } mode="aspectFill" />
      <RestaurantDetail>
        <Text>{name}</Text>
        <RatingStars rating={ score } numOfScore={ numOfScore }/>
        <View style={{flexGrow: '1'}} />
        <RestaurantTime>营业时间: {start_time} ~ {end_time}</RestaurantTime>
      </RestaurantDetail>
    </RestaurantItemView>
  )
}

const RestaurantItemView = styled(View)`
  width: 100%;
  box-sizing: border-box;
  margin: 20px 0;
  padding: 24px;

  background: white;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.35);
  
  display: flex;

  border:2px solid #dadada;
`

const RestaurantImage = styled(Image)`
  width: 130px;
  height: 130px;
  border-radius: 10px;
`

const RestaurantDetail = styled(View)`
  margin-left: 20px;
  display: flex;
  flex-direction: column;
`

const RestaurantTime = styled(Text)`
  font-size: 28px;
  font-weight: bold;
`